package com.tsingteng.cosfun.ui.message.officalnotification;

import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.base.BasePresenterFragment;
import com.tsingteng.cosfun.bean.NotificationBean;
import com.tsingteng.cosfun.bean.SystemNotificationBean;
import com.tsingteng.cosfun.common.Navigate;
import com.tsingteng.cosfun.widget.MyRecycleView;
import com.tsingteng.cosfun.widget.TitleView;

import butterknife.BindView;
/**
 * 官方助手列表
 * 常胜
 * 2018.8.15
 * */
public class OfficalNotificationFragment extends BasePresenterFragment<OfficalPresenter, OfficalNotificationContract.IOfficalView> implements OfficalNotificationContract.IOfficalView {
    @BindView(R.id.tv_official)
    TitleView tvOfficial;
    @BindView(R.id.rv_official_rv)
    MyRecycleView rvOfficialRv;
    private String type = "HELPER";
    private int page = 1;

    public static OfficalNotificationFragment newInstance() {
        OfficalNotificationFragment fragment = new OfficalNotificationFragment();
        return fragment;
    }


    @Override
    protected void initData(View rootView) {
        mPresenter.loginOfficalData(type,page);
        tvOfficial.setTitle("官方助手");
        tvOfficial.setIvLeft(R.drawable.back_big_icon);
        tvOfficial.setOnTitleClickListener(new TitleView.OnTitleClickListener() {
            @Override
            public void onLeft() {
                getActivity().finish();
            }

            @Override
            public void onRight() {

            }

            @Override
            public void onRight2() {

            }
        });
    }

    @Override
    protected OfficalPresenter createPresenter() {
        return new OfficalPresenter();
    }

    @Override
    protected View initHeader() {
        return null;
    }

    @Override
    protected MyRecycleView createRecycleView() {
        return rvOfficialRv;
    }

    @Override
    protected OfficalRecyAdapter createAdapter() {
        return new OfficalRecyAdapter();
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    public void onLoadMoreRequested() {
        page++;
        mPresenter.loginOfficalData(type,page);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_official_assistant;
    }

    @Override
    public void showOfficalData(SystemNotificationBean notificationBean) {
        if (rvOfficialRv!= null) rvOfficialRv.refreshComplete();
        if (notificationBean == null || notificationBean.getList()==null) return;
        if (notificationBean.isHasNextPage()) {
            mAdapter.loadMoreComplete();
        }else {
            mAdapter.loadMoreEnd();
        }
        mAdapter.addData(notificationBean.getList());
        mAdapter.notifyDataSetChanged();
    }


    @Override
    protected void refresh() {
        page = 1;
        mPresenter.loginOfficalData(type,page);
    }



}
